import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-01-04
 * Time: 20:57
 */
public class Test {
    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(10);
        arrayList.add(20);
        arrayList.add(30);
        //第一种遍历方式
        System.out.println(arrayList);
        //第2种遍历方式  for
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.print(arrayList.get(i)+" ");
        }
        System.out.println();
        //3、for-each
        for(int x : arrayList) {
            System.out.print(x+" ");
        }
        System.out.println();
        //4、迭代器
        Iterator<Integer> it = arrayList.iterator();
        while (it.hasNext()) {
            System.out.print(it.next()+" ");
        }
        System.out.println();
        //5、
        ListIterator<Integer> it2 = arrayList.listIterator();
        while (it2.hasNext()) {
            System.out.print(it2.next()+" ");
        }
        System.out.println();

        //6、从后向前打印
        ListIterator<Integer> it3 =
                arrayList.listIterator(arrayList.size());
        while (it3.hasPrevious()) {
            System.out.print(it3.previous()+" ");
        }
        System.out.println();
    }

}

